<template>

    <div class="wrap">

        <!-- 视频播放器 -->
       
        <template v-if="currentType == '1'">

            <div v-for="(item, index) in videos">
                <video class="video" autoplay v-show="currentIndex === index" :src="item" :key="index"
                    @ended="playNextVideo" controls :ref="el => setRefs(el, index)"></video>

            </div>
        </template>
        <template v-else-if="currentType == '0'">
           
            <el-carousel height="100vh" :interval="5000" v-if="imgs&&imgs.length>0">
                <el-carousel-item v-for="item in imgs" :key="item">
                    <div class="img_container">
                       
                        <img :src="item" style="width: 100%;height:auto;"/>
                    </div>

                </el-carousel-item>
            </el-carousel>
            <!-- <div style="width:100%;height:100vh;background-color: #f5f5f5;font-size:40px">欢迎光临</div> -->

        </template>


        <div class="main_container" v-if="shoppingCarData.length > 0">
            <div class="top_wrap">
                <div class="weight_wrap">
                    <div>
                        <span>净重：</span>
                        <span>{{ weight }}</span>
                    </div>
                </div>
                <div class="tare_wrap">
                    <div>
                        <span>皮重：</span>
                        <span>{{ tare }}</span>
                    </div>
                </div>
            </div>
            <div class="table_wrap">
                <el-table :header-cell-style="{ backgroundColor: 'var(--el-color-primary)', color: '#fff' }" stripe
                    :data="shoppingCarData" class-name="my_table">


                    <el-table-column>
                        <template #header>
                            <div class="table_header">
                                <div>商品</div>
                                <div>数/重量</div>
                                <div>小计</div>
                            </div>
                        </template>
                        <template #default="scope">
                            <div class="goods_name" style="font-size: 20px;">

                                {{ scope.row.goodsName }}
                            </div>
                            <div class="row">
                                <div class="red">
                                    <span > &yen;</span> <span style="font-size: 20px;">{{ scope.row.singlePrice }}</span>
                                </div>
                                <div style="font-size: 20px;">
                                    {{ scope.row.quantity }}

                                </div>
                                <div class="red">
                                    <span> &yen;</span>
                                    <span style="font-size: 20px;">{{ scope.row.rowPrice }}</span>
                                    
                                </div>


                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="discount">
                <!--  -->
                <div class="row" v-if="activityDiscountPrice * 1 > 0">
                    <span>活动优惠：</span>
                    <span>&yen;{{ activityDiscountPrice }}</span>
                </div>
                <!--  -->
                <div class="row" v-if="couponDiscountPrice * 1 > 0">
                    <span>优惠券抵：</span>
                    <span>&yen;{{ couponDiscountPrice }}</span>
                </div>
            </div>
            <div class="total">
                <span>应付：</span>
                <span>&yen;{{ shouldReceivePrice }}</span>
            </div>

        </div>

    </div>

</template>

<script setup lang="ts">
// @ts-nocheck
import NP from "number-precision";
import { ref, onMounted, nextTick, computed, watch } from 'vue'
const weight = ref('0.000')
const tare = ref('0.000')
const currentActiveVariableIndex = ref(0)
const shoppingCarData = ref([])
const shouldReceivePrice = ref('') //应付
const activityDiscountPrice = ref('') //活动优惠
const couponDiscountPrice = ref('') //优惠券抵扣
const typeList = ref(['video', 'img'])
const currentTypeIndex = ref('0') //当前类型 默认为
const fileList = ref([])
const currentIndex = ref(1)
// const videos = ref([
//     // 'https://vipmp4i.vodfile.m1905.com/202412240746/741922758119751a0d408ecf99fef4b2/video/moss/2024/12/22/v20241222A4IAJPZ9BIT1AXLQ/v20241222A4IAJPZ9BIT1AXLQ.mp4',
//     // 'https://vipmp4i.vodfile.m1905.com/202412240747/f5320a3989967f91479cbd1106b60f18/video/moss/2024/12/20/v202412209A5HLNAFNR8H0TH8/v202412209A5HLNAFNR8H0TH8.mp4',
//     // 'https://vipmp4i.vodfile.m1905.com/202412240747/3c62357423fdd567b81171219d96190b/video/moss/2024/12/10/v20241210SO0O876DHTSBJAQR/v20241210SO0O876DHTSBJAQR.mp4'
// ])
const videoRefs = ref([])
const currentType = computed(() => {
    return fileList.value[0] && fileList.value[0].type || '0' //默认图片
})

const videos = computed(() => {
    return currentType.value == '1' ? fileList.value.map(item => item.file) : []
})
const imgs = computed(() => {

    return currentType.value == '0' ? fileList.value.map(item => item.file) : []
})

//应付金额
// const computedReceivePrice = computed(() => {
//     return shoppingCarData.value[currentActiveVariableIndex.value].reduce((prev, currentVal) => {

//         return NP.plus(prev, NP.times(currentVal.quantity, currentVal.buyingPrice))
//     }, 0)
// })

//读取称重 重量
window.electron.ipcRenderer.on('get-weight-secondscreen', (_, data) => {

weight.value = data.weight
    tare.value = data.tare

})
window.electron.ipcRenderer.on('get-file-list', (_, data) => {

    fileList.value = data
})

// window.electron.ipcRenderer.on('change-variable-index', (_, index) => {
//     currentActiveVariableIndex.value = index
// })
// window.electron.ipcRenderer.on('change-shoppingcardata', (_, data) => {
//     console.log(data)
//     shoppingCarData.value = data
// })

window.electron.ipcRenderer.on('secondwindow-shoppingcardata', (_, data) => {
    // console.log(data)
    // console.log(222)
    shoppingCarData.value = data.list
    shouldReceivePrice.value = data.shouldReceivePrice
    activityDiscountPrice.value = data.activityDiscountPrice
    couponDiscountPrice.value = data.couponDiscountPrice
})


onMounted(() => {


    // if (currentType.value == 'video') {
    //     if (videoRefs.value[0]) {
    //         console.log(videoRefs.value[0])
    //         videoRefs.value[0].play()
    //     }
    // } else if (currentType.value == 'img') {

    // }


})


function setRefs(el, index) { //动态设置ref
    if (el) {
        videoRefs.value[index] = el
    }
}

function playNextVideo() {
    currentIndex.value = (currentIndex.value + 1) % videos.value.length;

    videoRefs.value[currentIndex.value].play()
}


</script>

<style lang="scss" scoped>
.wrap{
    font-size: 26px;
}
/*全屏*/
.video {
    position: fixed;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    // z-index: -1;
}

.img_container {
    width: 100%;
    height: 100vh;

    img {
        width: 100%;
        height: auto;
    }
}

.wrap {
    :deep(.el-carousel__indicators) {
        display: none;
    }
}

.top_wrap {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
}

.main_container {
    position: absolute;
    right: 0;
    top: 0;
    z-index: 10;
    // background-color: red;
    width: 40%;
    height: 100vh;
    overflow: hidden;
    background-color: #000;
    color: #fff;

    .weight_wrap {
        height: 50px;
        line-height: 50px;
    }

    .table_wrap {
        height: calc(100% - 162px);
        overflow: hidden;


        border: 1px solid var(--el-border-color);
        border-bottom: 0;
        box-sizing: border-box;

        .empty_wrap {
            height: calc(100vh - 50px - 95px - 40px - 5px - 40px - 101px - 14px);
            display: flex;
            flex-direction: column;
            justify-content: center;
            box-sizing: border-box;
            overflow: hidden;

            :deep(.el-empty) {
                padding: 0;
                height: 100%;
                overflow: hidden;
            }
        }

        .my_table {
            width: 100%;
            height: 100%;

            .table_header {
                display: flex;

                &>div {
                    flex: 1;
                    width: 33.33%;
                }
            }

            .goods_name {
                color: var(--el-text-color-primary);
            }

            .row {
                display: flex;

                &>div {
                    flex: 1;
                    width: 33.33%;
                }

                .red {
                    color: var(--el-color-danger);
                    // font-weight: bold;
                }

            }
        }


    }

    .discount {
        .row {
            display: flex;
            justify-content: space-between;
            padding: 0 10px;
            height: 30px;
            line-height: 30px;
            border-bottom: 1px solid #a19d9d;
        }

    }

    .total {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 10px;
        height: 50px;
        line-height: 50px;
    }
}
</style>